var year = 2019;
var mounth = 5;

document.querySelector("#nian").innerHTML = year;
document.querySelector("#yue").innerHTML = mounth;


var days = 0;

function ruiNian(y){
    if (y % 400 === 0 || (y % 4 === 0 && y % 100 !== 0)){
        return true
    }else {
        return false
    }
}
for (i=1980;i<2019;i++){
    if(ruiNian(i)){
        days += 366;
    }else {
        days += 365;
    }
}
console.log(days);




for (var o=1; o<mounth;o++){
    switch (o){
        case 1:
            days += 31;
            break;
        case 2:
            if (ruiNian(year)){
                days += 29;
            }else {
                days += 28;
            }
            break;
        case 3:
            days += 31;
            break;
        case 4:
            days += 30;
            break;
        case 5:
            days += 31;
            break;
        case 6:
            days += 30;
            break;
        case 7:
            days += 31;
            break;
        case 8:
            days += 31;
            break;
        case 9:
            days += 30;
            break;
        case 10:
            days += 31;
            break;
        case 11:
            days += 30;
            break;
        case 12:
            days += 31;
            break
    }
}




var day = 0;
    switch (mounth){
        case 1:
            day += 31;
            break;
        case 2:
            if (ruiNian(year)){
                day += 29;
            }else {
                day += 28;
            }
            break;
        case 3:
            day += 31;
            break;
        case 4:
            day += 30;
            break;
        case 5:
            day += 31;
            break;
        case 6:
            day += 30;
            break;
        case 7:
            day += 31;
            break;
        case 8:
            day += 31;
            break;
        case 9:
            day += 30;
            break;
        case 10:
            day += 31;
            break;
        case 11:
            day += 30;
            break;
        case 12:
            day += 31;
            break
    }


var g = 0;
switch (mounth-1){
    case 1:
        g += 31;
        break;
    case 2:
        if (ruiNian(year)){
            g += 29;
        }else {
            g += 28;
        }
        break;
    case 3:
        g += 31;
        break;
    case 4:
        g += 30;
        break;
    case 5:
        g += 31;
        break;
    case 6:
        g += 30;
        break;
    case 7:
        g += 31;
        break;
    case 8:
        g += 31;
        break;
    case 9:
        g += 30;
        break;
    case 10:
        g += 31;
        break;
    case 11:
        g += 30;
        break;
    case 12:
        g += 31;
        break
}
//因为1980年前面空余2个位置 我想让他从周日开始算
days += 2;
console.log(days);


//算出本月一号星期几 起始位置
var sh = days % 7;
console.log(sh);
//日历有多少格子
var num = 42;


//算一下 这个月结束 42个格子还剩下几个 用下个也月补上

var liu = num - sh - day;




//取到今天是几号
var thisdate = new Date().getDate();
var date1 = document.querySelector("#date1");

for (var j = g -sh +1;j <=g;j++){
    date1.innerHTML += "<span class='h'>"+j+"</span>";
}
for (var a=1;a<=day;a++){
    if (a == thisdate){
        date1.innerHTML += "<span class='today'>" + a + "</span>"
    }else {
        date1.innerHTML += "<span>" + a +  "</span>"
    }
}
for (var  s=1;s<=liu;s++){
    date1.innerHTML += "<span class='h'>" + s + "</span>"
}